'''
字典
'''
#1.创建
#空
dict01 = {}
dict01 = dict()
#默认值
dict01 = {"wj":100,"zm":80}
dict01 = dict([("a","b"),("c","d")])
print(dict01)

#2. 查找元素(根据键找值)
print(dict01['a'])
#如果key不存在，查找时会报错
#如果存在key则查找
if "ss" in dict01:
    print(dict01['ss'])

#3.修改元素(之前存在key)
dict01['a'] = "bb"
print(dict01['a'])

#4.添加（之前不存在key）
dict01['e'] = 'f'
print(dict01)

#5.删除
del dict01['a']
print(dict01)

#6.遍历  (获取字典所有元素)
#获取key
for key in dict01:
    print(key)
    print(dict01[key])

#获取values
for values in dict01.values():
    print(values)

#获取键值对 key：values(元组)
# for item in dict01.items():
#     print(item[0])
#     print(item[1])

for k,v in dict01.items():
    print(k)
    print(v)